<template>
  <el-dialog title='中心对应机构修改' :visible.sync='isShow' width='650px' :lock-scroll="false" :close-on-click-modal="false" @close='reset()' @open="init()">
    <div v-loading="loading">
      <el-card class='type-info-box-card'>
        <el-form ref='queryForm' size='mini' :model="queryForm" label-width="140px" :rules="rules" label-position="center">
          <el-row :gutter="30">
            <el-col>
              <!-- <el-form-item label='中心编号' class='typeInfo-el-form-item' prop='CENTERID'>
                <select-tree  ref="tree" v-model="queryForm.CENTERID"  :single-check="true" :props='{id:"branchId",label: "branchName",children: "childBranch"}' :tree-data="brno" style="width:350px" ></select-tree>
              </el-form-item>
              <el-form-item label='机构编号' class='typeInfo-el-form-item' prop='BRANCHNO'>
                <select-tree ref="tree" v-model="queryForm.BRANCHNO" :single-check="true" :props='{id:"branchId",label: "branchName",children: "childBranch"}' :tree-data="brno" style="width:350px" ></select-tree>
              </el-form-item> -->
              <el-form-item label='中心编号' class='typeInfo-el-form-item' prop='CENTERID'>
                <el-input v-model='queryForm.CENTERID' placeholder="请输入中心编号"></el-input>
              </el-form-item>
              <el-form-item label='中心名称' class='typeInfo-el-form-item' prop='CENTERNAME'>
                <el-input v-model='queryForm.CENTERNAME' placeholder="请输入中心名称"></el-input>
              </el-form-item>
              <el-form-item label='机构编号' class='typeInfo-el-form-item' prop='BRANCHNO'>
                <el-input v-model='queryForm.BRANCHNO' placeholder="请输入机构编号"></el-input>
              </el-form-item>
              <el-form-item label='机构名称' class='typeInfo-el-form-item' prop='BRANCHNONAME'>
                <el-input v-model='queryForm.BRANCHNONAME' placeholder="请输入机构名称"></el-input>
              </el-form-item>
              <el-form-item label='启用标识' class='typeInfo-el-form-item' prop='USEFLAG' style="width:350px">
                <el-radio v-model='queryForm.USEFLAG' label="0">启用</el-radio>
                <el-radio v-model='queryForm.USEFLAG' label="1">不启用</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <div slot="footer" style="margin:10px 0;text-align:center">
        <el-button size="mini" @click="isShow=false">取消</el-button>
        <el-button type='primary' size='mini' @click="submit">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import request from "@/common/utils/requestCT";
  import updInfo from "@/message/CTManage/branch-center/cloud-teller-branch-upd";
  import spinnerList from "@/message/spinnerDataQuery/spinner-data-query";
  import selectTree from "@/components/selectTree2/";
  export default {
    components: {
      selectTree
    },
    data() {
      return {
        brnoc: [],
        brno: [],
        loading: false,
        queryForm: { //表单数据
          CENTERID: '',
          BRANCHNO: '',
          CENTERNAME: '',
          BRANCHNONAME: '',
          USEFLAG: '',
        },
        rules: { //表单校验规则          
          CENTERID: [{
            required: true,
            message: "请选择中心编号",
            trigger: "change"
          }],
          CENTERNAME: [{
            required: true,
            message: "请输入中心名称",
            trigger: "blur"
          }],
          BRANCHNO: [{
            required: true,
            message: "请选择机构",
            trigger: "change"
          }],
          BRANCHNONAME: [{
            required: true,
            message: "请输入机构名称",
            trigger: "blur"
          }],
        }
      };
    },
    props: {
      option: Object,
      message: Array
    },
    computed: {
      isShow: {
        get: function() {
          return this.option.isShow;
        },
        set: function(newValue) {
          this.option.isShow = newValue;
        }
      },
    },
    methods: {
      async init() {
        this.queryForm.CENTERID = this.message[0].CENTERID
        this.queryForm.CENTERNAME = this.message[0].CENTERNAME
        this.queryForm.BRANCHNO = this.message[0].BRANCHNO;
        this.queryForm.BRANCHNONAME = this.message[0].BRANCHNONAME;
        this.queryForm.USEFLAG = this.message[0].USEFLAG;
        // let resBody = new spinnerList();
        // resBody.data.spinnerList = [{
        //   spinnerName: "branch"
        // }];
        // let response = await request(resBody);
        // if (response.SYS_HEAD.ReturnCode == "000000") {
        //   this.brno = response.RSP_BODY.branchSpinner;
        //   // for(let i=0;i<this.brno;i++){
        //   //   this.brno[i].push({disabled:true})
        //   // }
        //   this.brnoc = response.RSP_BODY.branchSpinner[0].childBranch;
        // } else {
        //   this.$message({
        //     type: "error",
        //     message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
        //   });
        // }
      },
      reset() {
        if (this.$refs["queryForm"]) {
          this.$refs["queryForm"].resetFields();
        }
      },
      submit() {
        this.$refs["queryForm"].validate(valid => {
          if (valid) {
            this.loading = true;
            let resBody = new updInfo();
            resBody.data.CENTERID = this.queryForm.CENTERID;
            resBody.data.BRANCHNO = this.queryForm.BRANCHNO;
            resBody.data.CENTERNAME = this.queryForm.CENTERNAME;
            resBody.data.BRANCHNONAME = this.queryForm.BRANCHNONAME;
            resBody.data.oldCENTERID = this.message[0].CENTERID;
            resBody.data.oldBRANCHNO = this.message[0].BRANCHNO;
            resBody.data.USEFLAG = this.queryForm.USEFLAG;
      
            request(resBody)
              .then(response => {
                this.loading = false;
                if (response.SYS_HEAD.ReturnCode == "000000") {
                  this.$message({
                    type: "success",
                    message: "操作成功！"
                  });
                  this.isShow = false;
                  this.$emit("refreshTable");
                } else {
                  this.$message({
                    type: "error",
                    message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
                  });
                }
              })
              .catch(error => {
                console.log(error);
                this.$message({
                  type: "warning",
                  message: "页面出错！"
                });
                this.loading = false;
              })
          }
        })
      }
    },
  };
</script>

<style lang="scss" scope>

</style>
